package com.trade.dao.websiteDAO;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.commons.beanutils.PropertyUtils;
import com.trade.commen.commMethodMgr;
import com.sys.dbm.Dbexecute;
import com.sys.log.Logger;

public class WebsiteExt extends WebsiteDAO{
    WebsiteDAO daoEntity;
	Logger log;
	ArrayList updArray;
	ArrayList paramArray;
	public WebsiteExt(){
		daoEntity = new WebsiteDAO();
		log  = new Logger(this);
		updArray  = new ArrayList();
		paramArray = new ArrayList();
	}

	public ArrayList selByList(String selBy){
		Dbexecute exec = new Dbexecute();
		ArrayList dataArray = new ArrayList();
		exec.setStrTable("tf_f_website");
		exec.setStrQuery(selBy);
		exec.setParamList(this.paramArray);
		dataArray =  exec.selBizQuery();
		if (dataArray.size()<=0) return null;
		return dataArray;
	}
	
	public WebsiteDAO selByInfo(String selBy){
		Dbexecute exec = new Dbexecute();
		commMethodMgr commen = new commMethodMgr();
		Logger log  = new Logger(this);
		ArrayList dataArray = new ArrayList();
		exec.setStrTable("tf_f_website");
		exec.setStrQuery(selBy);
		exec.setParamList(this.paramArray);
		dataArray = exec.selBizQuery();
		if (dataArray.size()<=0) return null;
		WebsiteDAO  daoEntity = new WebsiteDAO();
		Field[] fields = daoEntity.getClass().getDeclaredFields();
		for(Iterator it = dataArray.iterator(); it.hasNext();)
		{
			HashMap tradetype = (HashMap)it.next();
			for (int i=0;i<=fields.length-1;i++)
			{			
				if (tradetype.containsKey(fields[i].getName()))
				{
					try
					{
						if (tradetype.get(fields[i].getName()) !=null)
						{
							if (fields[i].getType().getName() =="java.lang.String")
							{
								PropertyUtils.setProperty(daoEntity, fields[i].getName(), tradetype.get(fields[i].getName()).toString());
							}
							else if (fields[i].getType().getName() =="java.lang.Integer") 
							{
								Integer ivalue = new Integer(tradetype.get(fields[i].getName()).toString());
								PropertyUtils.setProperty(daoEntity, fields[i].getName(), ivalue);
							}
						}
					}
					catch (InvocationTargetException e)
					{		
						throw new RuntimeException(e);
					}
					catch (NoSuchMethodException  e)
					{		
						throw new RuntimeException(e);
					}
					catch (IllegalAccessException e)
					{		
						throw new RuntimeException(e);
					}
				}
			}
		}
		return daoEntity;
	}
	public int selCount(String selBy){
		Dbexecute exec = new Dbexecute();
		return 0;
	}
	public void setParam(String paramName,Object paramValue){
		HashMap paramMap = new HashMap();
		paramMap.put("paramName", paramName);
		paramMap.put("paramValue", paramValue);
		this.paramArray.add(paramMap);
	}
	public ArrayList insBy(String insBy){
		ArrayList qInsBy = new ArrayList();
		HashMap paramMap = new HashMap();
		paramMap.put("queryTable", "tf_f_website");
		paramMap.put("queryString", insBy);
		paramMap.put("queryVarMap", this.paramArray);
		qInsBy.add(paramMap);
		return qInsBy;
	}
	 public ArrayList selByList(String selBy,int iStart,int iCount){
    	Dbexecute exec = new Dbexecute();
    	ArrayList dataArray = new ArrayList();
    	exec.setStrTable("tf_f_website");
    	exec.setStrQuery(selBy);
    	exec.setParamList(this.paramArray);
    	dataArray =  exec.selBizQuery(iStart,iCount);
    	if (dataArray.size()<=0) return null;
    	return dataArray;
    }	
}
